// pagesProperty/pages/event/point/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Dialog from '../../../../component/vant/dialog/dialog';
import Toast from '../../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    point_id: 0,
    loading: false,
    netWork: false,
    isLoading: true,
    hasData:false,
    recordList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log("options",options)
    var that = this;
    if(options.q){
      var q = decodeURIComponent(options.q) // 获取到二维码原始链接内容
      const scancode_time = parseInt(options.scancode_time) // 获取用户扫码时间 UNIX 时间戳
      
      q = "?" + q.split("?")[1];
      this.data.query = q;
      console.log('q',q)
      options = common_Js.getQueryVariable(q);
      console.log('options',options)
      var id = parseInt(options.id) 
      that.data.point_id = id
    }else{
      if(options.id){
        that.data.point_id = options.id
      }
    }
    this.onHttpInit()
  },
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/plan/point/preview', {
      point_id: that.data.point_id,
    }, function (res) {
      console.log("获取点位的巡检记录", res)
      if (res.data.code == 0) {
        if (res.data.totalcount > 0) {
          that.data.pageIndex = that.data.pageIndex + 1
          console.log("订单列表数据", res)
          var userRecords = res.data.data.userRecords;
          if(userRecords.length > 0){
            for (var index in userRecords) {
              that.data.recordList.splice(that.data.recordList.length, 0, userRecords[index]);
            }
            that.setData({
              hasData: true,
              recordList: that.data.recordList
            })
          }
        }
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
      that.setData({ netWork: true, isLoading: false, })
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false, })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  goDetail(e){
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../result/index?record_id=' + item.id
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.onHttpInit()
  },
  initOp:function(){
    this.setData({
      loading: false,
      netWork: false,
      isLoading: true,
      hasData:false,
      orderList:[]
    })
    this.onHttpInit()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({
      isLoading: true
    })
    this.onHttpInit()
  },
})